<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>用户资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
 <link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css" media="all">
</head>
<body layadmin-themealias="default">
          <div class="layui-fluid">   
          <div class="layui-card">
          <div class="layui-card-body">
<form class="layui-form" action="" style="margin-top: 20px;margin-bottom:50px;">
  <div class="layui-form-item">
    <label class="layui-form-label">组织名称</label>
    <div class="layui-input-inline">
      <input type="text" id="name" readonly="true" value="<#if deptDTO?? && deptDTO.name??>${deptDTO.name!}</#if>" autocomplete="off" placeholder="组织名称" class="layui-input">
    </div>
  </div>
  
  
      <div class="layui-form-item">
    <label class="layui-form-label">设置小区</label>
    <div class="layui-input-block">
    	<#list allVillageList as village>
      <input type="checkbox" name="villageId" value="${village.id}" title="${village.name}" <#if village.isChecked=="1">checked</#if> >
    	</#list>
    </div>
  </div>
  <input type="hidden" id="deptId" name="deptId" value="<#if deptDTO??>${deptDTO.id}</#if>" >

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" id=""  lay-submit="" lay-filter="dataSaveSubmit"  type="button">立即提交</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="backList();"  >返回</button>
    </div>
  </div>
</form>
</div>
    </div>
  </div>
<script type="text/javascript" src="${resRoot}/layui/layui.js"></script>
<script src="${resRoot}/js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript" src="${resRoot}/js/ajaxfileupload.js"></script>
<script>
function backList() {
	layer.closeAll("iframe");
    //刷新父页面
    parent.location.reload();
}

layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length < 5){
        return '用户名必须不小于5';
      }
    }
    ,pass: [/(.+){6,18}$/, '密码必须6到18位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  //监听提交
  form.on('submit(demo1)', function(data){
    layer.alert(JSON.stringify(data.field), {
      title: '最终的提交信息'
    })
    return false;
  });
  
  
  /* $("#submitBtn").click(function(){
	 	var id = $("#id").val();
		
		
		
	 	console.log(roleId)

	 $.ajax({
		 type : "post",
		 url : "${base}/sys/dept/saveDeptVillage",
		 data : {
			  id : id,
			  villageIds : villageIds
			 },
		 dataType : "json",
		 async : false,
		 success : function(data) {
			 flag  = data.message;
				if(flag == 1) {
					layer.msg('保存成功！', {
						  icon: 1,
						  time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							backList();
						});  
				} else {
					layer.alert("数据错误，请完善数据！");
				}
		 }
	 });
}); */
  
  
  form.on('submit(dataSaveSubmit)', function(data){
      var index = layer.msg('加载中...',{icon: 16,time:false,shade:0.8});
      var villageIds = "";
		$("input[name='villageId']:checkbox:checked").each(function(){ 
		villageIds= villageIds + $(this).val() +","; 
		}) 
		data.field.villageId = villageIds
		console.log(data.field)
      $.ajax({
			url : "${base}/sys/dept/saveDeptVllage",
			contentType : "application/json",
         	dataType : 'json',
			data : JSON.stringify(data.field),
          	type:'post',
			async : true,
			success : function(data) {
				layer.close(index);
				console.log(data)
				if(data.code == 1) {
						layer.msg('保存成功！', {
						  icon: 1,
						  time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function(){
							backList();
						});   
					} else {
						layer.msg(data.msg); 
					}
			}
		}); 
    });
  
});


	</script>

</body>
</html>